Repository navigation
lib: read class and type names for logs without nameof's fixed offsets - #24
Merged
Merged
Conversation
The csmeta/csname log helpers (className()) and csexpression/cstype took type names from nameof, which cuts them out of __PRETTY_FUNCTION__ at fixed offsets matching older GCC versions. With GCC 13 the computed length is negative, that is huge, so each log line printing a class or type name read far past the string and the node died with a segmentation fault. 58 warning and error lines use them, three of them on network input (Compressor decompression errors). Found on the test network: a pruned node crashed in Node::getBlockRequest, logging "unable to load block" with csmeta(cslog) as a joining node asked for blocks it had pruned (core dump backtrace: getBlockRequest -> boost::log formatted_write). cs::reflection::typeName<T>() reads the name from the compiler's signature by its "T = " marker instead, for GCC and clang; other compilers keep nameof. Lib test Reflection.TypeNamesAreExact pins the names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
csmeta/csnamelog helpers (className()) andcsexpression/cstypetake type names from nameof. nameof cuts the name out of__PRETTY_FUNCTION__at fixed offsets (GCC:+98,-151) that match the signature format of older GCC versions. With GCC 13 the computed length is negative, i.e. close toSIZE_MAX:Every log line that prints a class or type name therefore reads far past the string, and the node dies with a segmentation fault. 58 warning and error lines use these helpers. Most are on error paths; three are on network input (
Compressordecompression errors), so on such a build a malformed packet from a peer could take the node down.Official release binaries are built with an older GCC and are probably unaffected. Any build with a current toolchain is affected.
Found on the test network. A pruned node (#22) crashed when a joining node asked it for blocks it had pruned. The core dump backtrace:
The line is
csmeta(cslog) << "unable to load block " ..., which runs only when a requested block is missing.Fix
cs::reflection::typeName<T>()inlib/include/lib/system/reflection.hppreads the name from the compiler's signature by itsT =marker, for GCC ([with T = X; ...]) and clang ([T = X]). Other compilers keep nameof.className(),csexpressionandcstypeuse it. No other file changes.Verification
Reflection.TypeNamesAreExact. It checks a polymorphic class, a plain struct,cstype(int)andcsexpression.systemtests pass 50/50,nodetests134/134.🤖 Generated with Claude Code